<template>
  <div class="result-list">
    <div class="list-content">
      <el-table
        :data="resultList"
        style="width: 100%"
      >
        <el-table-column
          prop="docName"
          label="文件名称"
        />
        <el-table-column
          prop="createTime"
          label="时间"
          :formatter="timeFormatter"
        />
        <el-table-column
          label="操作"
          width="100"
        >
          <template slot-scope="scope">
            <el-button type="text" size="small" icon="el-icon-download" @click="handleDownload(scope.row)">下载</el-button>
          </template>
        </el-table-column>
      </el-table>
      <br>
      <br>
      <br>
    </div>
  </div>
</template>

<script>
import { getFileByKey } from '@/utils/global'
import moment from 'moment'
import { mapState } from 'vuex'
import util from '@/utils'
export default {
  components: {},
  data() {
    return {
      resultList: []
    }
  },
  computed: {
    ...mapState({
      device: (state) => state.app.device
    })
  },
  mounted() {
    const rid = util.getUrlSearch('rid')
    if (rid !== undefined && rid !== null && rid !== '') {
      this.getResultList(rid)
    } else {
      this.$message({
          message: 'rid不能为空！',
          type: 'warning'
        })
    }
  },
  methods: {
    getResultList(relativeId) {
      const fileParams = {
        fileType: 'file',
        dataSource: 'GLODON',
        relativeId
      }
      this.$api.upload.getFileInfo(fileParams).then((res) => {
        if (res.code === 200) {
          if (res.data.length > 0) {
            this.resultList = res.data
          }
        }
      })
    },
    timeFormatter(row, column, cellValue, index) {
       return cellValue !== undefined && cellValue !== null && cellValue !== '' ? moment(cellValue).format('YYYY-MM-DD HH:mm:ss') : ''
    },
    handleDownload(row) {
      const downUrl =
              getFileByKey +
              '?fileName=' +
              row.docName +
              row.docType +
              '&objectKey=' +
              row.docPath
            util.downloadCommonFile(downUrl, row.docName + row.docType)
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
